package com.peng.rpc.serializer;

/**
 * @author Wonderson
 * @email wpp.ds@foxmail.com
 * @date 2022/3/1 20:24
 */
public interface CommonSerializer {

    Integer KRYO_SERIALIZER = 0;
    Integer JSON_SERIALIZER = 1;
    Integer HESSIAN_SERIALIZER = 2;
    Integer PROTOBUF_SERIALIZER = 3;

    byte[] serialize(Object object);

    Object deserialize(byte[] bytes, Class<?> clazz);

    int getCode();

    static CommonSerializer getSerializerByCode(int code) {
        switch (code) {
            case 0: return new KryoSerializer();
            case 1: return new JsonSerializer();
            case 2: return new HessianSerializer();
            case 3: return new ProtobufSerializer();
            default: return  null;
        }
    }
}
